5 * Created by Sarah Westcott on 4/21/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "readcolumn.h"
11 #include "progress.hpp"
13 /***********************************************************************/
15 ReadColumnMatrix::ReadColumnMatrix(string df) : distFile(df){
17 successOpen = openInputFile(distFile, fileHandle);
21 /***********************************************************************/
23 int ReadColumnMatrix::read(NameAssignment* nameMap){
26 string firstName, secondName;
28 int nseqs = nameMap->size();
30 list = new ListVector(nameMap->getListVector());
32 Progress* reading = new Progress("Reading matrix: ", nseqs * nseqs);
35 int refRow = 0; //we'll keep track of one cell - Cell(refRow,refCol) - and see if it's transpose
36 int refCol = 0; //shows up later - Cell(refCol,refRow). If it does, then its a square matrix
38 //need to see if this is a square or a triangular matrix...
40 while(fileHandle && lt == 1){ //let's assume it's a triangular matrix...
43 fileHandle >> firstName >> secondName >> distance; // get the row and column names and distance
45 if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }
47 map<string,int>::iterator itA = nameMap->find(firstName);
48 map<string,int>::iterator itB = nameMap->find(secondName);
50 if(itA == nameMap->end()){
51 cerr << "AAError: Sequence '" << firstName << "' was not found in the names file, please correct\n"; exit(1);
53 if(itB == nameMap->end()){
54 cerr << "ABError: Sequence '" << secondName << "' was not found in the names file, please correct\n"; exit(1);
57 if (distance == -1) { distance = 1000000; }
58 else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert.
60 if(distance < cutoff && itA != itB){
61 if(itA->second > itB->second){
62 PCell value(itA->second, itB->second, distance);
64 if(refRow == refCol){ // in other words, if we haven't loaded refRow and refCol...
69 else if(refRow == itA->second && refCol == itB->second){
76 else if(itA->second < itB->second){
77 PCell value(itB->second, itA->second, distance);
79 if(refRow == refCol){ // in other words, if we haven't loaded refRow and refCol...
84 else if(refRow == itB->second && refCol == itA->second){
91 reading->update(itA->second * nseqs);
96 if(lt == 0){ // oops, it was square
98 fileHandle.close(); //let's start over
99 D->clear(); //let's start over
101 openInputFile(distFile, fileHandle); //let's start over
104 fileHandle >> firstName >> secondName >> distance;
106 if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }
108 map<string,int>::iterator itA = nameMap->find(firstName);
109 map<string,int>::iterator itB = nameMap->find(secondName);
111 if(itA == nameMap->end()){
112 cerr << "BError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
114 if(itB == nameMap->end()){
115 cerr << "BError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
118 if (distance == -1) { distance = 1000000; }
119 else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert.
121 if(distance < cutoff && itA->second > itB->second){
122 PCell value(itA->second, itB->second, distance);
124 reading->update(itA->second * nseqs);
131 if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }
141 catch(exception& e) {
142 m->errorOut(e, "ReadColumnMatrix", "read");
147 /***********************************************************************/
149 ReadColumnMatrix::~ReadColumnMatrix(){