cerr << "Decompressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
system(command.c_str());
cerr << "Done decompressing " << completeFileName << "\n";
- remove(tempName.c_str());
+ mothurRemove(tempName);
exit(EXIT_SUCCESS);
} else {
cerr << "waiting on child process " << fork_result << "\n";
cerr << "Decompressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
system(command.c_str());
cerr << "Done decompressing " << completeFileName << "\n";
- remove(tempName.c_str());
+ mothurRemove(tempName);
exit(EXIT_SUCCESS);
} else {
cerr << "waiting on child process " << fork_result << "\n";
string command = "mv " + oldName + " " + newName;
system(command.c_str());
#else
- remove(newName.c_str());
+ mothurRemove(newName);
int renameOk = rename(oldName.c_str(), newName.c_str());
#endif
return 0;
output.close();
//remove temp files
- remove(tempDistFile.c_str());
- remove(tempOutfile.c_str());
+ mothurRemove(tempDistFile);
+ mothurRemove(tempOutfile);
#endif
return outfile;
}
}
/**************************************************************************************************/
-vector<unsigned long int> MothurOut::setFilePosFasta(string filename, int& num) {
+vector<unsigned long long> MothurOut::setFilePosFasta(string filename, int& num) {
try {
- vector<unsigned long int> positions;
+ vector<unsigned long long> positions;
ifstream inFASTA;
- openInputFile(filename, inFASTA);
+ //openInputFile(filename, inFASTA);
+ inFASTA.open(filename.c_str(), ios::binary);
string input;
+ unsigned long long count = 0;
while(!inFASTA.eof()){
- input = getline(inFASTA);
- if (input.length() != 0) {
- if(input[0] == '>'){ unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); }
+ //input = getline(inFASTA);
+ //cout << input << '\t' << inFASTA.tellg() << endl;
+ //if (input.length() != 0) {
+ // if(input[0] == '>'){ unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); cout << (pos - input.length() - 1) << endl; }
+ //}
+ //gobble(inFASTA); //has to be here since windows line endings are 2 characters and mess up the positions
+ char c = inFASTA.get(); count++;
+ if (c == '>') {
+ positions.push_back(count-1);
+ //cout << count << endl;
}
- gobble(inFASTA); //has to be here since windows line endings are 2 characters and mess up the positions
}
inFASTA.close();
fclose (pFile);
}*/
- unsigned long int size = positions[(positions.size()-1)];
+ unsigned long long size = positions[(positions.size()-1)];
ifstream in;
openInputFile(filename, in);
in.close();
positions.push_back(size);
+ positions[0] = 0;
return positions;
}
}
}
/**************************************************************************************************/
-vector<unsigned long int> MothurOut::setFilePosEachLine(string filename, int& num) {
+vector<unsigned long long> MothurOut::setFilePosEachLine(string filename, int& num) {
try {
filename = getFullPathName(filename);
- vector<unsigned long int> positions;
+ vector<unsigned long long> positions;
ifstream in;
- openInputFile(filename, in);
-
+ //openInputFile(filename, in);
+ in.open(filename.c_str(), ios::binary);
+
string input;
+ unsigned long long count = 0;
+ positions.push_back(0);
+
while(!in.eof()){
- unsigned long int lastpos = in.tellg();
- input = getline(in);
- if (input.length() != 0) {
- unsigned long int pos = in.tellg();
- if (pos != -1) { positions.push_back(pos - input.length() - 1); }
- else { positions.push_back(lastpos); }
+ //unsigned long long lastpos = in.tellg();
+ //input = getline(in);
+ //if (input.length() != 0) {
+ //unsigned long long pos = in.tellg();
+ //if (pos != -1) { positions.push_back(pos - input.length() - 1); }
+ //else { positions.push_back(lastpos); }
+ //}
+ //gobble(in); //has to be here since windows line endings are 2 characters and mess up the positions
+
+
+ //getline counting reads
+ char d = in.get(); count++;
+ while ((d != '\n') && (d != '\r') && (d != '\f') && (d != in.eof())) {
+ //get next character
+ d = in.get();
+ count++;
}
- gobble(in); //has to be here since windows line endings are 2 characters and mess up the positions
+
+ if (!in.eof()) {
+ d=in.get(); count++;
+ while(isspace(d) && (d != in.eof())) { d=in.get(); count++;}
+ }
+ positions.push_back(count-1);
+ cout << count-1 << endl;
}
in.close();
- num = positions.size();
+ num = positions.size()-1;
FILE * pFile;
- unsigned long int size;
+ unsigned long long size;
//get num bytes in file
pFile = fopen (filename.c_str(),"rb");
fclose (pFile);
}
- positions.push_back(size);
+ positions[(positions.size()-1)] = size;
return positions;
}
}
/**************************************************************************************************/
-vector<unsigned long int> MothurOut::divideFile(string filename, int& proc) {
+vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
try{
- vector<unsigned long int> filePos;
+ vector<unsigned long long> filePos;
filePos.push_back(0);
FILE * pFile;
- unsigned long int size;
+ unsigned long long size;
filename = getFullPathName(filename);
}
//estimate file breaks
- unsigned long int chunkSize = 0;
+ unsigned long long chunkSize = 0;
chunkSize = size / proc;
//file to small to divide by processors
//for each process seekg to closest file break and search for next '>' char. make that the filebreak
for (int i = 0; i < proc; i++) {
- unsigned long int spot = (i+1) * chunkSize;
+ unsigned long long spot = (i+1) * chunkSize;
ifstream in;
openInputFile(filename, in);
in.seekg(spot);
//look for next '>'
- unsigned long int newSpot = spot;
+ unsigned long long newSpot = spot;
while (!in.eof()) {
char c = in.get();
if (c == '>') { in.putback(c); newSpot = in.tellg(); break; }
}
//there was not another sequence before the end of the file
- unsigned long int sanityPos = in.tellg();
+ unsigned long long sanityPos = in.tellg();
if (sanityPos == -1) { break; }
else { filePos.push_back(newSpot); }
int MothurOut::divideFile(string filename, int& proc, vector<string>& files) {
try{
- vector<unsigned long int> filePos = divideFile(filename, proc);
+ vector<unsigned long long> filePos = divideFile(filename, proc);
for (int i = 0; i < (filePos.size()-1); i++) {
ifstream in;
openInputFile(filename, in);
in.seekg(filePos[i]);
- unsigned long int size = filePos[(i+1)] - filePos[i];
+ unsigned long long size = filePos[(i+1)] - filePos[i];
char* chunk = new char[size];
in.read(chunk, size);
in.close();
exit(1);
}
}
+/***********************************************************************/
+void MothurOut::mothurRemove(string filename){
+ try {
+ filename = getFullPathName(filename);
+ remove(filename.c_str());
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "mothurRemove");
+ exit(1);
+ }
+}
/**************************************************************************************************/
vector<vector<double> > MothurOut::binomial(int maxOrder){