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
38 in >> numTest >> name;
40 if (!m->isContainingOnlyDigits(numTest)) { m->mothurOut("[ERROR]: expected a number and got " + numTest + ". I suspect you entered a column formatted file as a phylip file, quitting."); m->mothurOutEndLine(); exit(1); }
41 else { convert(numTest, numSeqs); }
43 while((d=in.get()) != EOF){
45 //is d a number meaning its square
51 //is d a line return meaning its lower triangle
60 //reopen and read now that you know whether you are square
62 m->openInputFile(distFile, f);
70 for(int i=0;i<rank;i++)
71 matrix[i].resize(rank);
72 for(int i=0;i<rank;i++) {
74 for(int j=0;j<rank;j++) {
75 if (m->control_pressed) { return names; }
78 if (matrix[i][j] == -0.0000)
79 matrix[i][j] = 0.0000;
84 for(int i=0;i<rank;i++){
85 matrix[i].resize(rank);
87 matrix[0][0] = 0.0000;
89 for(int i=1;i<rank;i++){
93 if (m->control_pressed) { return names; }
95 if (matrix[i][j] == -0.0000)
96 matrix[i][j] = 0.0000;
97 matrix[j][i]=matrix[i][j];
105 catch(exception& e) {
106 m->errorOut(e, "ReadPhylipVector", "read");
110 /***********************************************************************/
111 vector<string> ReadPhylipVector::read(vector<seqDist>& matrix) {
113 vector<string> names;
116 m->openInputFile(distFile, in);
118 //check whether matrix is square
124 in >> numSeqs >> name;
126 while((d=in.get()) != EOF){
128 //is d a number meaning its square
134 //is d a line return meaning its lower triangle
143 //reopen and read now that you know whether you are square
145 m->openInputFile(distFile, f);
153 for(int i=0;i<rank;i++) {
155 for(int j=0;j<rank;j++) {
156 if (m->control_pressed) { return names; }
160 if (j < i) { //only save lt
161 seqDist dist(i, j, temp);
162 matrix.push_back(dist);
167 else if(square == 2){
169 for(int i=1;i<rank;i++){
171 for(int j=0;j<i;j++){
172 if (m->control_pressed) { return names; }
174 seqDist dist(i, j, temp);
175 matrix.push_back(dist);
183 catch(exception& e) {
184 m->errorOut(e, "ReadPhylipVector", "read");
188 /***********************************************************************/