5 * Created by westcott on 1/11/11.
6 * Copyright 2011 Schloss Lab. All rights reserved.
10 #include "readphylipvector.h"
12 /***********************************************************************/
13 ReadPhylipVector::ReadPhylipVector(string d) {
15 m = MothurOut::getInstance();
19 m->errorOut(e, "ReadPhylipVector", "ReadPhylipVector");
23 /***********************************************************************/
24 vector<string> ReadPhylipVector::read(vector< vector<double> >& matrix) {
29 m->openInputFile(distFile, in);
31 //check whether matrix is square
37 in >> numSeqs >> name;
39 while((d=in.get()) != EOF){
41 //is d a number meaning its square
47 //is d a line return meaning its lower triangle
56 //reopen and read now that you know whether you are square
58 m->openInputFile(distFile, f);
66 for(int i=0;i<rank;i++)
67 matrix[i].resize(rank);
68 for(int i=0;i<rank;i++) {
70 for(int j=0;j<rank;j++) {
71 if (m->control_pressed) { return names; }
74 if (matrix[i][j] == -0.0000)
75 matrix[i][j] = 0.0000;
80 for(int i=0;i<rank;i++){
81 matrix[i].resize(rank);
83 matrix[0][0] = 0.0000;
85 for(int i=1;i<rank;i++){
89 if (m->control_pressed) { return names; }
91 if (matrix[i][j] == -0.0000)
92 matrix[i][j] = 0.0000;
93 matrix[j][i]=matrix[i][j];
101 catch(exception& e) {
102 m->errorOut(e, "ReadPhylipVector", "read");
106 /***********************************************************************/
107 vector<string> ReadPhylipVector::read(vector<seqDist>& matrix) {
109 vector<string> names;
112 m->openInputFile(distFile, in);
114 //check whether matrix is square
120 in >> numSeqs >> name;
122 while((d=in.get()) != EOF){
124 //is d a number meaning its square
130 //is d a line return meaning its lower triangle
139 //reopen and read now that you know whether you are square
141 m->openInputFile(distFile, f);
149 for(int i=0;i<rank;i++) {
151 for(int j=0;j<rank;j++) {
152 if (m->control_pressed) { return names; }
156 if (j < i) { //only save lt
157 seqDist dist(i, j, temp);
158 matrix.push_back(dist);
163 else if(square == 2){
165 for(int i=1;i<rank;i++){
167 for(int j=0;j<i;j++){
168 if (m->control_pressed) { return names; }
170 seqDist dist(i, j, temp);
171 matrix.push_back(dist);
179 catch(exception& e) {
180 m->errorOut(e, "ReadPhylipVector", "read");
184 /***********************************************************************/