]> git.donarmstrong.com Git - mothur.git/blobdiff - splitmatrix.cpp
changes while testing
[mothur.git] / splitmatrix.cpp
index 28bc5d4cec4fc4ec409bca26359ed103951c8701..f6b5c4d81cf5446adc5e5253808380be7ebbf28d 100644 (file)
@@ -182,7 +182,7 @@ int SplitMatrix::createDistanceFilesFromTax(map<string, int>& seqGroup, int numG
                }
                
                copyGroups.clear();
-               
+        
                //process each distance file
                for (int i = 0; i < numGroups; i++) { 
                        
@@ -191,8 +191,12 @@ int SplitMatrix::createDistanceFilesFromTax(map<string, int>& seqGroup, int numG
             else { options = "fasta=" + (fastafile + "." + toString(i) + ".temp") + ", processors=" + toString(processors) + ", cutoff=" + toString(distCutoff); }
                        if (outputDir != "") { options += ", outputdir=" + outputDir; }
                        
+            m->mothurOut("/******************************************/"); m->mothurOutEndLine(); 
+            
                        Command* command = new DistanceCommand(options);
                        
+            m->mothurOut("/******************************************/"); m->mothurOutEndLine(); 
+            
                        command->execute();
                        delete command;
                        
@@ -203,6 +207,9 @@ int SplitMatrix::createDistanceFilesFromTax(map<string, int>& seqGroup, int numG
             else { m->mothurRemove((countfile + "." + toString(i) + ".temp")); }
                }
         
+        //restore old fasta file name since dist.seqs overwrites it with the temp files
+        m->setFastaFile(fastafile);
+        
         vector<string> tempDistFiles;    
         for(int i=0;i<numGroups;i++){
             if (outputDir == "") { outputDir = m->hasPath(fastafile); }
@@ -328,7 +335,7 @@ int SplitMatrix::splitDistanceLarge(){
                
                int numGroups = 0;
 
-               ofstream outFile;
+               //ofstream outFile;
                ifstream dFile;
                m->openInputFile(distFile, dFile);
        
@@ -404,6 +411,7 @@ int SplitMatrix::splitDistanceLarge(){
                                                                                        
                                        //have we reached the max buffer size
                                        if (numOutputs[groupID] > 60) { //write out sequence
+                        ofstream outFile;
                                                outFile.open(fileName.c_str(), ios::app);
                                                outFile << outputs[groupID] << seqA << '\t' << seqB << '\t' << dist << endl;
                                                outFile.close();
@@ -430,7 +438,7 @@ int SplitMatrix::splitDistanceLarge(){
                                                        //if groupB is written to file it is above buffer size so read and write to new merged file
                                                        if (wroteOutPut[groupIDB]) {
                                                                string fileName2 = distFile + "." + toString(groupIDB) + ".temp";
-                                                               ifstream fileB(fileName2.c_str(), ios::ate);
+                                                               /*ifstream fileB(fileName2.c_str(), ios::ate);
                                                                
                                                                outFile.open(fileName.c_str(), ios::app);
                                                                
@@ -465,17 +473,22 @@ int SplitMatrix::splitDistanceLarge(){
                                                                outFile << temp.substr(0, lastRead);
                                                                delete memblock;
                                                                
-                                                               fileB.close();
+                                                               fileB.close();*/
+                                m->appendFiles(fileName2, fileName);
                                                                m->mothurRemove(fileName2);
+                        
                                                                
                                                                //write out the merged memory
                                                                if (numOutputs[groupID] > 60) {
-                                                                       outFile << outputs[groupID];
+                                    ofstream tempOut;
+                                    m->openOutputFile(fileName, tempOut);
+                                                                       tempOut << outputs[groupID];
                                                                        outputs[groupID] = "";
                                                                        numOutputs[groupID] = 0;
+                                    tempOut.close();
                                                                }
                                                                
-                                                               outFile.close();
+                                                               //outFile.close();
                                                                
                                                                wroteOutPut[groupID] = true;
                                                                wroteOutPut[groupIDB] = false;
@@ -490,7 +503,7 @@ int SplitMatrix::splitDistanceLarge(){
                                                        
                                                        if (wroteOutPut[groupIDA]) {
                                                                string fileName2 = distFile + "." + toString(groupIDA) + ".temp";
-                                                               ifstream fileB(fileName2.c_str(), ios::ate);
+                                                               /*ifstream fileB(fileName2.c_str(), ios::ate);
                                                                
                                                                outFile.open(fileName.c_str(), ios::app);
                                                                
@@ -525,17 +538,21 @@ int SplitMatrix::splitDistanceLarge(){
                                                                        
                                                                delete memblock;
                                                                
-                                                               fileB.close();
+                                                               fileB.close();*/
+                                m->appendFiles(fileName2, fileName);
                                                                m->mothurRemove(fileName2);
                                                                
                                                                //write out the merged memory
                                                                if (numOutputs[groupID] > 60) {
-                                                                       outFile << outputs[groupID];
+                                    ofstream tempOut;
+                                    m->openOutputFile(fileName, tempOut);
+                                                                       tempOut << outputs[groupID];
                                                                        outputs[groupID] = "";
                                                                        numOutputs[groupID] = 0;
+                                    tempOut.close();
                                                                }
                                                                
-                                                               outFile.close();
+                                                               //outFile.close();
                                                                
                                                                wroteOutPut[groupID] = true;
                                                                wroteOutPut[groupIDA] = false;
@@ -555,6 +572,7 @@ int SplitMatrix::splitDistanceLarge(){
             //remove old names files just in case
                        
                        if (numOutputs[i] > 0) {
+                ofstream outFile;
                                outFile.open(fileName.c_str(), ios::app);
                                outFile << outputs[i];
                                outFile.close();
@@ -637,7 +655,7 @@ int SplitMatrix::splitNames(map<string, int>& seqGroup, int numGroups, vector<st
                     ofstream out;
                     string newtempNameFile = tempNameFile + "2";
                     m->openOutputFile(newtempNameFile, out);
-                    out << headers << endl;
+                    out << "Representative_Sequence\ttotal" << endl;
                     out.close();
                     m->appendFiles(tempNameFile, newtempNameFile);
                     m->mothurRemove(tempNameFile);
@@ -671,7 +689,7 @@ int SplitMatrix::splitNames(map<string, int>& seqGroup, int numGroups, vector<st
             ofstream out;
             string newtempNameFile = singleton + "2";
             m->openOutputFile(newtempNameFile, out);
-            out << headers << endl;
+            out << "Representative_Sequence\ttotal" << endl; 
             out.close();
             m->appendFiles(singleton, newtempNameFile);
             m->mothurRemove(singleton);