]> git.donarmstrong.com Git - mothur.git/blob - readdistcommand.cpp
broke apart read matrix file
[mothur.git] / readdistcommand.cpp
1 /*
2  *  readdistcommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 1/20/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "readdistcommand.h"
11 #include "readphylip.h"
12 #include "readcolumn.h"
13
14 ReadDistCommand::ReadDistCommand(){
15         try {
16                 globaldata = GlobalData::getInstance();
17                 
18                 filename = globaldata->inputFileName;
19                 format = globaldata->getFormat();       
20                 
21                 if (format == "column") { read = new ReadColumnMatrix(filename); }      
22                 else if (format == "phylip") { read = new ReadPhylipMatrix(filename); }
23                 else if (format == "matrix") { 
24                                 groupMap = new GroupMap(globaldata->getGroupFile());
25                                 groupMap->readMap();
26                                 //if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap;  }
27                                 globaldata->gGroupmap = groupMap;
28                 }
29                 
30                 if (format != "matrix" ) {
31                         if(globaldata->getPrecision() != ""){
32                                 convert(globaldata->getPrecision(), precision); 
33                         }
34                 
35                         if(globaldata->getCutOff() != ""){
36                                 convert(globaldata->getCutOff(), cutoff);       
37                                 cutoff += (5 / (precision * 10.0));
38                         }
39                         read->setCutoff(cutoff);
40         
41                         if(globaldata->getNameFile() != ""){    
42                                 nameMap = new NameAssignment(globaldata->getNameFile());
43                                 nameMap->readMap(1,2);
44                         }
45                         else{
46                                 nameMap = NULL;
47                         }
48                 }
49                         
50         }
51         catch(exception& e) {
52                 cout << "Standard Error: " << e.what() << " has occurred in the ReadDistCommand class Function ReadDistCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53                 exit(1);
54         }
55         catch(...) {
56                 cout << "An unknown error has occurred in the ReadDistCommand class function ReadDistCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57                 exit(1);
58         }
59 }
60
61 //**********************************************************************************************************************
62 ReadDistCommand::~ReadDistCommand(){
63         delete read;
64         delete nameMap;
65 }
66
67 //**********************************************************************************************************************
68 int ReadDistCommand::execute(){
69         try {
70                 
71                 if (format == "matrix") {
72                         ifstream in;
73                         openInputFile(filename, in);
74                         matrix = new FullMatrix(in); //reads the matrix file
75                         //memory leak prevention
76                         //if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix;  }
77                         globaldata->gMatrix = matrix; //save matrix for coverage commands
78                 }else {
79                         read->read(nameMap);
80                         globaldata->gListVector = read->getListVector();
81                         globaldata->gSparseMatrix = read->getMatrix();
82                 }
83                 return 0;
84         }
85         catch(exception& e) {
86                 cout << "Standard Error: " << e.what() << " has occurred in the ReadDistCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
87                 exit(1);
88         }
89         catch(...) {
90                 cout << "An unknown error has occurred in the ReadDistCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
91                 exit(1);
92         }
93 }