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 void 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...
39 while(fileHandle && lt == 1){ //let's assume it's a triangular matrix...
41 fileHandle >> firstName >> secondName >> distance; // get the row and column names and distance
43 if(nameMap->count(firstName)==0){
44 cerr << "AError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
46 if(nameMap->count(secondName)==0){
47 cerr << "AError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
50 if (distance == -1) { distance = 1000000; }
52 if(distance < cutoff && nameMap->get(firstName) != nameMap->get(secondName)){
53 if(nameMap->get(firstName) > nameMap->get(secondName)){
54 PCell value(nameMap->get(firstName), nameMap->get(secondName), distance);
56 if(refRow == refCol){ // in other words, if we haven't loaded refRow and refCol...
57 refRow = nameMap->get(firstName);
58 refCol = nameMap->get(secondName);
61 else if(refRow == nameMap->get(firstName) && refCol == nameMap->get(secondName)){
68 else if(nameMap->get(firstName) < nameMap->get(secondName)){
69 PCell value(nameMap->get(secondName), nameMap->get(firstName), distance);
71 if(refRow == refCol){ // in other words, if we haven't loaded refRow and refCol...
72 refRow = nameMap->get(firstName);
73 refCol = nameMap->get(secondName);
76 else if(refRow == nameMap->get(secondName) && refCol == nameMap->get(firstName)){
83 reading->update(nameMap->get(firstName) * nseqs);
88 if(lt == 0){ // oops, it was square
89 fileHandle.close(); //let's start over
90 D->clear(); //let's start over
92 openInputFile(distFile, fileHandle); //let's start over
95 fileHandle >> firstName >> secondName >> distance;
97 if(nameMap->count(firstName)==0){
98 cerr << "BError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
100 if(nameMap->count(secondName)==0){
101 cerr << "BError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
104 if (distance == -1) { distance = 1000000; }
106 if(distance < cutoff && nameMap->get(firstName) > nameMap->get(secondName)){
107 PCell value(nameMap->get(firstName), nameMap->get(secondName), distance);
109 reading->update(nameMap->get(firstName) * nseqs);
116 // while(fileHandle){
117 // fileHandle >> firstName >> secondName >> distance;
119 // if(nameMap->count(firstName)==0){
120 // cerr << "CError: Sequence '" << firstName << "' was not found in the names file, please correct\n";
122 // if(nameMap->count(secondName)==0){
123 // cerr << "CError: Sequence '" << secondName << "' was not found in the names file, please correct\n";
125 // if (distance == -1) { distance = 1000000; }
127 // if(distance < cutoff && (*nameMap)[firstName].second < (*nameMap)[secondName].second){
128 //// cout << (*nameMap)[secondName] << ' ' << (*nameMap)[firstName] << ' ' << distance << endl;
129 // D->addCell(Cell((*nameMap)[secondName].second, (*nameMap)[firstName].second, distance));
130 // reading->update((*nameMap)[secondName].second * nseqs);
133 // gobble(fileHandle);
142 catch(exception& e) {
143 cout << "Standard Error: " << e.what() << " has occurred in the ReadColumnMatrix class Function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
147 cout << "An unknown error has occurred in the ReadColumnMatrix class function read. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
153 /***********************************************************************/
155 ReadColumnMatrix::~ReadColumnMatrix(){