X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=readcolumn.cpp;h=53a8c4263dddc4687acc5a64cf7c5b1d27aac647;hb=2bb9267aa4b4ecdf8488b06605cc9f3f36fa4332;hp=c03c37f1feeb888c341ca4daa01c644069c155a5;hpb=163b300cfd7d4ca4e70c454be20f07b1d8346650;p=mothur.git diff --git a/readcolumn.cpp b/readcolumn.cpp index c03c37f..53a8c42 100644 --- a/readcolumn.cpp +++ b/readcolumn.cpp @@ -14,13 +14,21 @@ ReadColumnMatrix::ReadColumnMatrix(string df) : distFile(df){ - successOpen = openInputFile(distFile, fileHandle); + successOpen = m->openInputFile(distFile, fileHandle); + sim = false; } +/***********************************************************************/ + +ReadColumnMatrix::ReadColumnMatrix(string df, bool s) : distFile(df){ + + successOpen = m->openInputFile(distFile, fileHandle); + sim = s; +} /***********************************************************************/ -void ReadColumnMatrix::read(NameAssignment* nameMap){ +int ReadColumnMatrix::read(NameAssignment* nameMap){ try { string firstName, secondName; @@ -38,20 +46,20 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){ //need to see if this is a square or a triangular matrix... while(fileHandle && lt == 1){ //let's assume it's a triangular matrix... + fileHandle >> firstName >> secondName >> distance; // get the row and column names and distance + + if (m->control_pressed) { fileHandle.close(); delete reading; return 0; } map::iterator itA = nameMap->find(firstName); map::iterator itB = nameMap->find(secondName); - - if(itA == nameMap->end()){ - cerr << "AAError: Sequence '" << firstName << "' was not found in the names file, please correct\n"; - } - if(itB == nameMap->end()){ - cerr << "ABError: Sequence '" << secondName << "' was not found in the names file, please correct\n"; - } + + 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; } + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. if(distance < cutoff && itA != itB){ if(itA->second > itB->second){ @@ -86,29 +94,29 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){ } reading->update(itA->second * nseqs); } - gobble(fileHandle); + m->gobble(fileHandle); } if(lt == 0){ // oops, it was square + fileHandle.close(); //let's start over D->clear(); //let's start over - openInputFile(distFile, fileHandle); //let's start over + m->openInputFile(distFile, fileHandle); //let's start over while(fileHandle){ fileHandle >> firstName >> secondName >> distance; + + if (m->control_pressed) { fileHandle.close(); delete reading; return 0; } map::iterator itA = nameMap->find(firstName); map::iterator itB = nameMap->find(secondName); - if(itA == nameMap->end()){ - cerr << "BError: Sequence '" << firstName << "' was not found in the names file, please correct\n"; - } - if(itB == nameMap->end()){ - cerr << "BError: Sequence '" << secondName << "' was not found in the names file, please correct\n"; - } + 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; } + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. if(distance < cutoff && itA->second > itB->second){ PCell value(itA->second, itB->second, distance); @@ -116,25 +124,24 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){ reading->update(itA->second * nseqs); } - gobble(fileHandle); + m->gobble(fileHandle); } } - + + if (m->control_pressed) { fileHandle.close(); delete reading; return 0; } + reading->finish(); fileHandle.close(); list->setLabel("0"); + + return 1; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ReadColumnMatrix class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ReadColumnMatrix", "read"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the ReadColumnMatrix class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - } /***********************************************************************/