#include "distancedb.hpp"
/**************************************************************************************************/
-Classify::Classify(string tfile, string tempFile, string method, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch) : taxFile(tfile), templateFile(tempFile) {
+void Classify::generateDatabaseAndNames(string tfile, string tempFile, string method, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch) {
try {
- m = MothurOut::getInstance();
+ taxFile = tfile;
readTaxonomy(taxFile);
+ templateFile = tempFile;
+
int start = time(NULL);
int numSeqs = 0;
MPI_Status status;
MPI_File inMPI;
MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
-
- char inFileName[tempFile.length()];
+
+ //char* inFileName = new char[tempFile.length()];
+ //memcpy(inFileName, tempFile.c_str(), tempFile.length());
+
+ char inFileName[1024];
strcpy(inFileName, tempFile.c_str());
-
+
MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer
-
+ //delete inFileName;
+
if (pid == 0) { //only one process needs to scan file
positions = setFilePosFasta(tempFile, numSeqs); //fills MPIPos, returns numSeqs
for(int i=0;i<numSeqs;i++){
//read next sequence
int length = positions[i+1] - positions[i];
- char buf4[length];
+ char* buf4 = new char[length];
MPI_File_read_at(inMPI, positions[i], buf4, length, MPI_CHAR, &status);
string tempBuf = buf4;
if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
-
+ delete buf4;
istringstream iss (tempBuf,istringstream::in);
Sequence temp(iss);
while (!fastaFile.eof()) {
Sequence temp(fastaFile);
gobble(fastaFile);
-
+
names.push_back(temp.getName());
}
fastaFile.close();
}
catch(exception& e) {
- m->errorOut(e, "Classify", "Classify");
+ m->errorOut(e, "Classify", "generateDatabaseAndNames");
exit(1);
}
}
/**************************************************************************************************/
+Classify::Classify() { m = MothurOut::getInstance(); database = NULL; }
+/**************************************************************************************************/
-void Classify::readTaxonomy(string file) {
+int Classify::readTaxonomy(string file) {
try {
phyloTree = new PhyloTree();
MPI_Status status;
MPI_File inMPI;
MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
+
+ //char* inFileName = new char[file.length()];
+ //memcpy(inFileName, file.c_str(), file.length());
- char inFileName[file.length()];
+ char inFileName[1024];
strcpy(inFileName, file.c_str());
-
+
MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer
-
+ //delete inFileName;
+
if (pid == 0) {
positions = setFilePosEachLine(file, num);
for(int i=0;i<num;i++){
//read next sequence
int length = positions[i+1] - positions[i];
- char buf4[length];
+ char* buf4 = new char[length];
MPI_File_read_at(inMPI, positions[i], buf4, length, MPI_CHAR, &status);
string tempBuf = buf4;
if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
-
+ delete buf4;
+
istringstream iss (tempBuf,istringstream::in);
iss >> name >> taxInfo;
taxonomy[name] = taxInfo;
phyloTree->assignHeirarchyIDs(0);
+ phyloTree->setUp(file);
+
m->mothurOut("DONE.");
m->mothurOutEndLine(); cout.flush();
+
+ return phyloTree->getNumSeqs();
}
catch(exception& e) {