]> git.donarmstrong.com Git - mothur.git/blobdiff - formatcolumn.cpp
forced rarefaction.single to output ending line for all groups. added subsample...
[mothur.git] / formatcolumn.cpp
index 64b85317d1303658627f4ed6cfde1f99b51d3677..6b29f90464f3259c6c625421d9ee1cadbc8b2ef8 100644 (file)
@@ -12,7 +12,7 @@
 
 /***********************************************************************/
 FormatColumnMatrix::FormatColumnMatrix(string df) : filename(df){
-       openInputFile(filename, fileHandle);
+       m->openInputFile(filename, fileHandle);
 }
 /***********************************************************************/
 
@@ -35,18 +35,18 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){
                
                ofstream out;
                string tempOutFile = filename + ".temp";
-               openOutputFile(tempOutFile, out);
+               m->openOutputFile(tempOutFile, out);
        
                while(fileHandle && lt == 1){  //let's assume it's a triangular matrix...
                
-                       if (m->control_pressed) { out.close(); remove(tempOutFile.c_str()); fileHandle.close();  delete reading; return 0; }
+                       if (m->control_pressed) { out.close();  m->mothurRemove(tempOutFile); fileHandle.close();  delete reading; return 0; }
                
                        fileHandle >> firstName >> secondName >> distance;      // get the row and column names and distance
        
                        map<string,int>::iterator itA = nameMap->find(firstName);
                        map<string,int>::iterator itB = nameMap->find(secondName);
-                       if(itA == nameMap->end()){      cerr << "AAError: Sequence '" << firstName << "' was not found in the names file, please correct\n"; exit(1);   }
-                       if(itB == nameMap->end()){      cerr << "ABError: Sequence '" << secondName << "' was not found in the names file, please correct\n"; exit(1);  }
+                       if(itA == nameMap->end()){  m->mothurOut("AAError: Sequence '" + firstName + "' was not found in the names file, please correct\n"); exit(1);  }
+                       if(itB == nameMap->end()){  m->mothurOut("ABError: Sequence '" + secondName + "' was not found in the names file, please correct\n"); exit(1);  }
 
                        if (distance == -1) { distance = 1000000; }
                
@@ -68,7 +68,7 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){
                                
                                reading->update(itA->second * nseqs / 2);
                        }
-                       gobble(fileHandle);
+                       m->gobble(fileHandle);
                }
                out.close();
                fileHandle.close();
@@ -79,10 +79,10 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){
                }else{ squareFile = tempOutFile; }
                
                //sort file by first column so the distances for each row are together
-               string outfile = getRootName(squareFile) + "sorted.dist.temp";
+               string outfile = m->getRootName(squareFile) + "sorted.dist.temp";
                
                //use the unix sort 
-               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                        string command = "sort -n " + squareFile + " -o " + outfile;
                        system(command.c_str());
                #else //sort using windows sort
@@ -90,14 +90,14 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){
                        system(command.c_str());
                #endif
                
-               if (m->control_pressed) { remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; }
+               if (m->control_pressed) { m->mothurRemove(tempOutFile); m->mothurRemove(outfile); delete reading; return 0; }
 
                //output to new file distance for each row and save positions in file where new row begins
                ifstream in;
-               openInputFile(outfile, in);
+               m->openInputFile(outfile, in);
                
                distFile = outfile + ".rowFormatted";
-               openOutputFile(distFile, out);
+               m->openOutputFile(distFile, out);
                
                rowPos.resize(nseqs, -1);
                int currentRow;
@@ -115,9 +115,9 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){
                
                while(!in.eof()) {
                        
-                       if (m->control_pressed) { in.close(); out.close(); remove(distFile.c_str()); remove(tempOutFile.c_str()); remove(outfile.c_str()); delete reading; return 0; }
+                       if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(distFile); m->mothurRemove(tempOutFile); m->mothurRemove(outfile); delete reading; return 0; }
                        
-                       in >> first >> second >> dist; gobble(in);
+                       in >> first >> second >> dist; m->gobble(in);
                        
                        if (first != currentRow) {
                                //save position in file of each new row
@@ -159,17 +159,17 @@ int FormatColumnMatrix::read(NameAssignment* nameMap){
                in.close();
                out.close();
                
-               if (m->control_pressed) {  remove(distFile.c_str()); remove(tempOutFile.c_str()); remove(outfile.c_str());  delete reading; return 0; }
+               if (m->control_pressed) {  m->mothurRemove(distFile); m->mothurRemove(tempOutFile); m->mothurRemove(outfile);  delete reading; return 0; }
                
-               remove(tempOutFile.c_str());
-               remove(outfile.c_str());
+               m->mothurRemove(tempOutFile);
+               m->mothurRemove(outfile);
                
                reading->finish();
                
                delete reading;
                list->setLabel("0");
                
-               if (m->control_pressed) {  remove(distFile.c_str());  return 0; }
+               if (m->control_pressed) {  m->mothurRemove(distFile);  return 0; }
 
                return 1;