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){ mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); }
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){ mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); }
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){ mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); }
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);
159 /* if(nameMap != NULL){
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 mothurOut("missed something\t" + toString(nameMap->size())); mothurOutEndLine();
170 catch(exception& e) {
171 errorOut(e, "ReadPhylipMatrix", "read");
176 /***********************************************************************/
178 ReadPhylipMatrix::~ReadPhylipMatrix(){