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];
100 catch(exception& e) {
101 m->errorOut(e, "ReadPhylipVector", "read");
105 /***********************************************************************/
106 vector<string> ReadPhylipVector::read(vector<seqDist>& matrix) {
108 vector<string> names;
111 m->openInputFile(distFile, in);
113 //check whether matrix is square
119 in >> numSeqs >> name;
121 while((d=in.get()) != EOF){
123 //is d a number meaning its square
129 //is d a line return meaning its lower triangle
138 //reopen and read now that you know whether you are square
140 m->openInputFile(distFile, f);
148 for(int i=0;i<rank;i++) {
150 for(int j=0;j<rank;j++) {
151 if (m->control_pressed) { return names; }
155 if (j < i) { //only save lt
156 seqDist dist(i, j, temp);
157 matrix.push_back(dist);
162 else if(square == 2){
164 for(int i=1;i<rank;i++){
166 for(int j=0;j<i;j++){
167 if (m->control_pressed) { return names; }
169 seqDist dist(i, j, temp);
170 matrix.push_back(dist);
177 catch(exception& e) {
178 m->errorOut(e, "ReadPhylipVector", "read");
182 /***********************************************************************/