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 = m->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);
56 //if (((itA->second == 8) && (itB->second == 1588)) || ((itA->second == 1588) && (itB->second == 8))) { cout << "found it" << endl; }
58 if (distance == -1) { distance = 1000000; }
59 else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert.
61 if(distance < cutoff && itA != itB){
62 if(itA->second > itB->second){
63 PCell value(itA->second, itB->second, distance);
65 if(refRow == refCol){ // in other words, if we haven't loaded refRow and refCol...
70 else if(refRow == itA->second && refCol == itB->second){
77 else if(itA->second < itB->second){
78 PCell value(itB->second, itA->second, distance);
80 if(refRow == refCol){ // in other words, if we haven't loaded refRow and refCol...
85 else if(refRow == itB->second && refCol == itA->second){
92 reading->update(itA->second * nseqs);
94 m->gobble(fileHandle);
97 if(lt == 0){ // oops, it was square
99 fileHandle.close(); //let's start over
100 D->clear(); //let's start over
102 m->openInputFile(distFile, fileHandle); //let's start over
105 fileHandle >> firstName >> secondName >> distance;
107 if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }
109 map<string,int>::iterator itA = nameMap->find(firstName);
110 map<string,int>::iterator itB = nameMap->find(secondName);
112 if(itA == nameMap->end()){
113 cerr << "BError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
115 if(itB == nameMap->end()){
116 cerr << "BError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
119 if (distance == -1) { distance = 1000000; }
120 else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert.
122 if(distance < cutoff && itA->second > itB->second){
123 PCell value(itA->second, itB->second, distance);
125 reading->update(itA->second * nseqs);
128 m->gobble(fileHandle);
132 if (m->control_pressed) { fileHandle.close(); delete reading; return 0; }
142 catch(exception& e) {
143 m->errorOut(e, "ReadColumnMatrix", "read");
148 /***********************************************************************/
150 ReadColumnMatrix::~ReadColumnMatrix(){