5 * Created by Sarah Westcott on 4/21/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "readphylip.h"
11 #include "progress.hpp"
13 /***********************************************************************/
15 ReadPhylipMatrix::ReadPhylipMatrix(string distFile){
17 successOpen = openInputFile(distFile, fileHandle);
21 /***********************************************************************/
23 void ReadPhylipMatrix::read(NameAssignment* nameMap){
29 vector<string> matrixNames;
31 fileHandle >> nseqs >> name;
33 matrixNames.push_back(name);
36 list = new ListVector(nseqs);
40 list = new ListVector(nameMap->getListVector());
41 if(nameMap->count(name)==0){ cout << "Error: Sequence '" << name << "' was not found in the names file, please correct" << endl; }
45 while((d=fileHandle.get()) != EOF){
49 fileHandle.putback(d);
50 for(int i=0;i<nseqs;i++){
51 fileHandle >> distance;
65 reading = new Progress("Reading matrix: ", nseqs * (nseqs - 1) / 2);
69 for(int i=1;i<nseqs;i++){
71 matrixNames.push_back(name);
73 //there's A LOT of repeated code throughout this method...
78 fileHandle >> distance;
80 if (distance == -1) { distance = 1000000; }
82 if(distance < cutoff){
83 PCell value(i, j, distance);
87 reading->update(index);
92 if(nameMap->count(name)==0){ cout << "Error: Sequence '" << name << "' was not found in the names file, please correct" << endl; }
95 fileHandle >> distance;
97 if (distance == -1) { distance = 1000000; }
99 if(distance < cutoff){
100 PCell value(nameMap->get(matrixNames[i]), nameMap->get(matrixNames[j]), distance);
104 reading->update(index);
111 reading = new Progress("Reading matrix: ", nseqs * nseqs);
115 for(int i=1;i<nseqs;i++){
117 matrixNames.push_back(name);
121 for(int j=0;j<nseqs;j++){
122 fileHandle >> distance;
124 if (distance == -1) { distance = 1000000; }
126 if(distance < cutoff && j < i){
127 PCell value(i, j, distance);
131 reading->update(index);
136 if(nameMap->count(name)==0){ cout << "Error: Sequence '" << name << "' was not found in the names file, please correct" << endl; }
138 for(int j=0;j<nseqs;j++){
139 fileHandle >> distance;
141 if (distance == -1) { distance = 1000000; }
143 if(distance < cutoff && j < i){
144 PCell value(nameMap->get(matrixNames[i]), nameMap->get(matrixNames[j]), distance);
148 reading->update(index);
160 for(int i=0;i<matrixNames.size();i++){
161 nameMap->erase(matrixNames[i]);
163 if(nameMap->size() > 0){
164 //should probably tell them what is missing if we missed something
165 cout << "missed something" << '\t' << nameMap->size() << endl;
170 catch(exception& e) {
171 cout << "Standard Error: " << e.what() << " has occurred in the ReadPhylipMatrix class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
175 cout << "An unknown error has occurred in the ReadPhylipMatrix class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
180 /***********************************************************************/
182 ReadPhylipMatrix::~ReadPhylipMatrix(){