5 * Created by Sarah Westcott on 4/21/09.
\r
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
\r
10 #include "readcolumn.h"
\r
11 #include "progress.hpp"
\r
13 /***********************************************************************/
\r
15 ReadColumnMatrix::ReadColumnMatrix(string df) : distFile(df){
\r
17 successOpen = openInputFile(distFile, fileHandle);
\r
21 /***********************************************************************/
\r
23 void ReadColumnMatrix::read(NameAssignment* nameMap){
\r
26 string firstName, secondName;
\r
28 int nseqs = nameMap->size();
\r
30 list = new ListVector(nameMap->getListVector());
\r
32 Progress* reading = new Progress("Reading matrix: ", nseqs * nseqs);
\r
35 int refRow = 0; //we'll keep track of one cell - Cell(refRow,refCol) - and see if it's transpose
\r
36 int refCol = 0; //shows up later - Cell(refCol,refRow). If it does, then its a square matrix
\r
38 //need to see if this is a square or a triangular matrix...
\r
40 while(fileHandle && lt == 1){ //let's assume it's a triangular matrix...
\r
42 fileHandle >> firstName >> secondName >> distance; // get the row and column names and distance
\r
44 map<string,int>::iterator itA = nameMap->find(firstName);
\r
45 map<string,int>::iterator itB = nameMap->find(secondName);
\r
47 if(itA == nameMap->end()){
\r
48 cerr << "AAError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
\r
50 if(itB == nameMap->end()){
\r
51 cerr << "ABError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
\r
54 if (distance == -1) { distance = 1000000; }
\r
56 if(distance < cutoff && itA != itB){
\r
57 if(itA->second > itB->second){
\r
58 PCell value(itA->second, itB->second, distance);
\r
60 if(refRow == refCol){ // in other words, if we haven't loaded refRow and refCol...
\r
61 refRow = itA->second;
\r
62 refCol = itB->second;
\r
65 else if(refRow == itA->second && refCol == itB->second){
\r
72 else if(itA->second < itB->second){
\r
73 PCell value(itB->second, itA->second, distance);
\r
75 if(refRow == refCol){ // in other words, if we haven't loaded refRow and refCol...
\r
76 refRow = itA->second;
\r
77 refCol = itB->second;
\r
80 else if(refRow == itB->second && refCol == itA->second){
\r
87 reading->update(itA->second * nseqs);
\r
92 if(lt == 0){ // oops, it was square
\r
93 fileHandle.close(); //let's start over
\r
94 D->clear(); //let's start over
\r
96 openInputFile(distFile, fileHandle); //let's start over
\r
99 fileHandle >> firstName >> secondName >> distance;
\r
101 map<string,int>::iterator itA = nameMap->find(firstName);
\r
102 map<string,int>::iterator itB = nameMap->find(secondName);
\r
104 if(itA == nameMap->end()){
\r
105 cerr << "BError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
\r
107 if(itB == nameMap->end()){
\r
108 cerr << "BError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
\r
111 if (distance == -1) { distance = 1000000; }
\r
113 if(distance < cutoff && itA->second > itB->second){
\r
114 PCell value(itA->second, itB->second, distance);
\r
116 reading->update(itA->second * nseqs);
\r
119 gobble(fileHandle);
\r
124 fileHandle.close();
\r
126 list->setLabel("0");
\r
129 catch(exception& e) {
\r
130 errorOut(e, "ReadColumnMatrix", "read");
\r
135 /***********************************************************************/
\r
137 ReadColumnMatrix::~ReadColumnMatrix(){
\r